<template>
	<view>
	<!-- 	<cu-custom bgColor="bg-gradual-blue" :isBack="false"><block slot="content">首页</block></cu-custom> -->
		<view class="content">
			<view v-if="hasLogin">
				<view>
					<uni-grid
						@click="clickGrid"
						:options="[
							{ image: 'https://img-cdn-qiniu.dcloud.net.cn/img/lindang.png', text: '参加考试' },
							{ image: 'https://img-cdn-qiniu.dcloud.net.cn/img/laoren.png', text: '查看成绩' },
							{ image: 'https://img-cdn-qiniu.dcloud.net.cn/img/shoutao.png', text: '回看试卷' }
						]"
					></uni-grid>
				</view>
			</view>
			<view v-if="!hasLogin" class="hello"><view class="title">您好 游客,请登录!</view></view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import uniGrid from '@/components/uni-grid/uni-grid.vue';
export default {
	components: { uniGrid },
	computed: mapState(['forcedLogin', 'hasLogin', 'user']),
	onLoad() {
		if (!this.hasLogin) {
			uni.showModal({
				title: '未登录',
				content: '您未登录，需要登录后才能继续',
				showCancel: !this.forcedLogin,
				success: res => {
					if (res.confirm) {
						/**
						 * 如果需要强制登录，使用reLaunch方式
						 */
						if (this.forcedLogin) {
							uni.reLaunch({
								url: '../login/login'
							});
						} else {
							uni.navigateTo({
								url: '../login/login'
							});
						}
					}
				}
			});
		} else {
		}
	},
	methods: {
		clickGrid(code) {
			//参见考试
			if (code.index == 0) {
				uni.navigateTo({
					url: '../exam/index'
				});
			} else if (code.index == 2) {
			uni.navigateTo({
				url: '../exam/presjhk'
			});
			} else if (code.index == 1) {
					uni.navigateTo({
					url: '../exam/cjcx'
				});
			}
		}
	}
};
</script>

<style>
.hello {
	display: flex;
	flex: 1;
	flex-direction: column;
}

.title {
	color: #8f8f94;
	margin-top: 50upx;
}

.ul {
	font-size: 30upx;
	color: #8f8f94;
	margin-top: 50upx;
}

.ul > view {
	line-height: 50upx;
}
</style>
